"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const { exec } = require('child_process');
async function getGPUUsage() {
    const command = 'nvidia-smi --query-gpu=utilization.gpu,memory.used,memory.free --format=csv';
    return new Promise((resolve, reject) => {
        exec(command, (error, stdout, stderr) => {
            if (error) {
                console.error(`错误: ${error.message}`);
                return null;
            }
            if (stderr) {
                console.error(`stderr: ${stderr}`);
                return null;
            }
            const result = stdout.split('\n');
            const pathLine = result[1].trim();
            const params = pathLine.split(',').map((param) => param.trim());
            const usedMem = Number(params[1].replace(' MiB', ''));
            const freeMem = Number(params[2].replace(' MiB', ''));
            const usage = {
                'gpuUsage': params[0],
                'freeMem': params[2],
                'totalMem': usedMem + freeMem + ' MiB',
                'usedMem': params[1],
                'MemUsage': Math.round(usedMem / (usedMem + freeMem) * 100) + '%'
            };
            resolve(usage);
        });
    });
}
exports.default = getGPUUsage;
